package edu.ccit.shudong.utils;

public class R<T> {

    // 状态码
    private Integer code;

    // 提示信息
    private String msg;

    // 内容
    private T data;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }


    //    静态函数，方便构造对象
    public static R ok() {
        R result = new R();
        result.setCode(200);
        result.setMsg("成功");
        result.setData("");
        return result;
    }

    public static R ok(String msg) {
        R result = new R();
        result.setCode(200);
        result.setMsg(msg);
        result.setData("");
        return result;
    }

    public static R ok(Object object) {
        R result = new R();
        result.setCode(200);
        result.setMsg("成功");
        result.setData(object);
        return result;
    }

    public static R ok(String msg, Object object) {
        R result = new R();
        result.setCode(200);
        result.setMsg(msg);
        result.setData(object);
        return result;
    }

    public static R error() {
        R result = new R();
        result.setCode(500);
        result.setMsg("失败");
        result.setData("");
        return result;
    }

    public static R error(Integer code, String msg) {
        R result = new R();
        result.setCode(code);
        result.setMsg(msg);
        result.setData("");
        return result;
    }

    public static R error(Object object) {
        R result = new R();
        result.setCode(500);
        result.setMsg("失败");
        result.setData(object);
        return result;
    }

    public static R error(String msg) {
        R result = new R();
        result.setCode(500);
        result.setMsg(msg);
        result.setData("");
        return result;
    }

    public static R error(String msg, Object object) {
        R result = new R();
        result.setCode(500);
        result.setMsg(msg);
        result.setData(object);
        return result;
    }

    public static R error(Integer code, String msg, Object object) {
        R result = new R();
        result.setCode(500);
        result.setMsg(msg);
        result.setData(object);
        return result;
    }
}